package prepare;

import java.io.*;

/**
 * Created by IntelliJ IDEA.
 * User: aleck
 * Date: 2007-10-18
 * Time: 2:13:12
 * To change this template use File | Settings | File Templates.
 */
public class TryUnicode {
  public static void main(String[] args) throws IOException {
    test00();
    //test01();
  }

  private static void test00() throws IOException {
    byte hi = (byte)209;
    byte lo = (byte)167;
    byte[] arr = new byte[]{hi, lo};
    ByteArrayInputStream bais = new ByteArrayInputStream(arr);
    InputStreamReader isr = new InputStreamReader(bais);
    BufferedReader br = new BufferedReader(isr);
    System.out.println(br.readLine());
    arr[1] = (byte)165;
    bais.reset();
    System.out.println(br.readLine());
  }

  private static void test01() throws UnsupportedEncodingException {
        StringBuilder sb = new StringBuilder(256);
//    char chrTemp = 'ѧ';
//    int iLow = chrTemp & 0xFF;
//    int iHigh = (chrTemp & 0xFF00) >> 8;
//
//    byte[] aryByte = new byte[]{(byte) iHigh, (byte) iLow};
//    String strTempUnicode = null;
//    try {
//     strTempUnicode = new String(aryByte, 0, 2, "Unicode");
//     byte[] aryByteResult = strTempUnicode.getBytes();
//
//     sb.insert(1, (char) (aryByteResult[1] & 0xFF));
//     sb.setCharAt(0, (char) (aryByteResult[0] & 0xFF));
//    } catch (UnsupportedEncodingException e) {
//     // TODO Auto-generated catch block
//     e.printStackTrace();
//    }

    byte hi = (byte)209;
    byte lo = (byte)167;
    char c = 'ѧ';
    String s = new String(new byte[]{hi, lo}, "GB3212");
    byte[] aryByteResult = s.getBytes();
    sb.insert(1, (char) (aryByteResult[1] & 0xFF));
    sb.setCharAt(0, (char) (aryByteResult[0] & 0xFF));

    System.out.println((int)c >> 8);
    System.out.println((int)c & 0xFF);
    System.out.println(c);
    s = Character.toString(c);
    System.out.println(s.getBytes()[0]);
    System.out.println(s.getBytes()[1]);
    System.out.println(sb.toString());
  }
}
